< previous page page_213 next page >

Page 213
The following code section handles the selection of the report destination. Notice that this code toggles the enabled/disabled properties of the file-related controls. The controls are kept disabled unless the user select the "file" destination option. Here's the code:
Private Sub opt3dDest_Click (Index As Integer, Value As Integer)
   Dim nFile As Integer
   '
   ' send report to window
   If opt3dDest(0) = True Then
      CrystalReport1.Destination = 0
      nFile = False
   End If
   '
   ' send report to printer
   If opt3dDest(1) = True Then
      CrystalReport1.Destination = 1
      nFile = False
   End If
   '
   ' send report to file
   If opt3dDest(2) = True Then
      CrystalReport1.Destination = 2
      nFile = True
   End If
   '
   ' enable/disable file controls
   txtFileName.Enabled = nFile
   cboFileTypes.Enabled = nFile
   cmdFileName.Enabled = nFile
End Sub
The next section of code calls the Visual Basic 5 common dialog box to allow the user to select a filename as the destination for the report output. Notice the use of the &H2 value in the Flags property. This forces the common dialog box to issue a warning message if the user selects a filename that already exists. Once a valid file is selected, it is loaded into a form-level variable for later use. Here's the code:
Private Sub cmdFileName_Click ()
   '
   ' set some parms
   CMDialog1.DialogTitle = "Save Report File Name"
   CMDialog1.Filter = "Text (*.txt)|*.txt|"
   CMDialog1.Flags = &H2
   '
   ' run the save as dialog
   CMDialog1.Action = 2
   '
   ' load the selected filename into control
   If Len(CMDialog1.Filename) > 0 Then
      cFileName = CMDialog1.Filename
   End If
   Me.txtFileName = cFileName
End Sub

 
< previous page page_213 next page >

If you like this book, buy it!